import { fileURLToPath, URL } from 'node:url'
import postCssPxToRem from "postcss-pxtorem"
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import Components from 'unplugin-vue-components/vite';
import { VantResolver } from '@vant/auto-import-resolver';
// const autoprefixer = require('autoprefixer');
// const px2rem = require('postcss-pxtorem');
// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    vueJsx(),
    Components({
      resolvers: [VantResolver()],
    })
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  css: {
    postcss: {
      plugins: [
        postCssPxToRem({
          rootValue: 37.5, // 1rem的大小
          propList: ['*'], // 需要转换的属性，这里选择全部都进行转换
        })
      ]
    }
  },
  server: {
    proxy: {
      '/sph-dev': {
        // 如果接口前缀是以 /app-dev 开头
        // 就会执行当前代理转发
        // 这时候完整的请求地址是 http://sph-h5-api.atguigu.cn/app-dev/admin/acl/index/login
        // 接口地址是不包含 /app-dev 的，因此需要进行路径重写
        // http://sph-h5-api.atguigu.cn/admin/acl/index/login
        target: 'http://sph-h5-api.atguigu.cn',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/app-dev/, '')
      },
      '/wy-dev': {
        target: 'https://m.you.163.com',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/app-dev/, '')
      }
    }
  }
})

